var app = app || {};
app.pendulum = {};
app.pendulum.LENGTH = 150;
app.pendulum.M = 1000;
app.pendulum.GRAVITY = 9.8;
app.pendulum.T = 1;

app.pendulum.angle = 0;
app.pendulum.direction = 0.01;
app.pendulum.velocity = 0;
app.pendulum.acceleration = app.pendulum.GRAVITY / app.pendulum.M;

(function($) {
	$(function() {
		var length = app.pendulum.LENGTH;
		var m = app.pendulum.M;
		var gravity = app.pendulum.GRAVITY;
		var t = app.pendulum.T;

		var angle = app.pendulum.angle;
		var velocity = app.pendulum.velocity;
		var acceleration = app.pendulum.acceleration;


		setInterval(function() {

			acceleration = ((gravity * Math.cos(angle)) / m) * t;

			velocity += acceleration * t;

			angle += velocity * t;
			var ballX = (length * Math.cos(angle)) + 150;
			var ballY = length * Math.sin(angle);

			$('#ball').css('left', ballX);
			$('#ball').css('top', ballY);

		}, (1000 / 24));
	});
})(jQuery);